<template>
  <layout title="icon图标" :custom-content-style="customLayoutStyle">
    <view class="icon">

      <tn-sticky :custom-navbar-height="customNavbar.height" top="10">
        <view class="icon__search">
          <input class="search-input" placeholder="请输入需要查找的图标" @input="handleInputEvent" />
        </view>
      </tn-sticky>

      <view class="icon__content tn-flex-start-start tn-flex-wrap">
        <view
          v-for="(item, index) in filterIconData"
          :key="index"
          class="icon__item tn-flex-column tn-flex-center"
          :style="itemStyle(index)"
          @tap.stop="handleItemClick(item.name)"
        >
          <view class="icon"><tn-icon :icon="item.name"></tn-icon></view>
          <view class="title tn-color-grey tn-text-ellipsis-1">{{ item.name }}</view>
        </view>
      </view>

      <view class="tn-text-center tn-margin-top-xl">
        <view>目前300+，里面缺少你想要的吗？</view>
        <view>请前往图鸟语雀留言写下你的需求叭</view>
      </view>
    </view>
  </layout>
</template>

<script lang="ts" setup>
import { ref, computed, CSSProperties } from 'vue'
import { iconData, TuniaoIconData } from './lib/icon'
import Layout from '@/components/layout/index.vue'
import TnIcon from '@/tuniao-ui/components/tn-icon/src/Icon.vue'
import TnSticky from '@/tuniao-ui/components/tn-sticky/src/Sticky.vue'
import { toast } from '@/tuniao-ui/utils'
import useSystemInfo from '@/tuniao-ui/libs/hooks/useSystemInfo'

// layout自定义样式
const customLayoutStyle: CSSProperties = {
  padding: 0
}

const { customNavbar } = useSystemInfo()

// item样式
const itemStyle = computed<(index: number) => CSSProperties>(() => {
  return (index: number) => {
    let style: CSSProperties = {}
    style.animationDelay = `${index > 30 ? 0 : index * 0.1}s`
    return style
  }
})

// 筛选图标
let filterIconData = ref<TuniaoIconData[]>(iconData)
const handleInputEvent = (e: any) => {
  console.log(e.detail.value);
  filterIconData.value = iconData.filter((item) => {
    return item.name.includes(e.detail.value)
  })
}

// 图标点击事件
const handleItemClick = (name: string) => {
  if (!name) return
  uni.setClipboardData({
    data: name,
    success: () => {
      toast({
        title: '复制成功'
      })
    }
  })
  setTimeout(() => {
    toast({
      icon: 'none',
      title: name,
      duration: 10000,
      mask: false
    })
  }, 1000);
}
</script>

<style lang="scss" scoped>

.icon {
  padding: 30rpx;

  &__content {
    margin-top: 40rpx;
  }

  &__item {
    width: 30.4%;
    background-color: #FFFFFF;
    border-radius: 10rpx;
    box-shadow: 1;
    padding: 30rpx;
    margin: 20rpx 10rpx;
    margin-top: 0;
    box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.06);
    animation: enterAnimation 0.1s cubic-bezier(0.68, -0.55, 0.265, 1.55) 1 forwards;
    transform: scale(0);
    transform-origin: center center;

    .icon {
      font-size: 60rpx;
      line-height: 1;
    }
    .title {
      width: 100%;
      text-align: center;
    }
  }

  &__search {
    margin-top: 20rpx;
    
    .search-input {
      background-color: #FFFFFF;
      border: 1rpx solid #E6E6E6;
      border-radius: 28rpx;
      font-size: 24rpx;
      height: 56rpx;
      line-height: 56rpx;
      text-align: center;

      &::-webkit-input-placeholder {
        color: #E6E6E6;
      }
    }
  }
}

@keyframes enterAnimation {
  0% {
    transform: scale(0);
  }
  100% {
    transform: scale(1);
  }
}
</style>
